﻿using B.R.RabbitRoot.Domain.animal_husbandry;
using B.R.RabbitRoot.ErrorCode;
using B.R.RabbitRoot.Infrastructure.Interface;
using B.R.RabbitRoot.Write.API.Applications.Commands.HealthCareCommands;
using MediatR;

namespace B.R.RabbitRoot.Write.API.Applications.Commandhandlers.HealthCareCommandHandler
{
    /// <summary>
    /// 删除健康信息命令处理
    /// </summary>
    public class HealthCareDeleteCommandHandler : IRequestHandler<HealthCareDeleteCommand, APIResult<int>>
    {
        private readonly IBaserepository<HealthCareInfo> _healthCareInfo;

        public HealthCareDeleteCommandHandler(IBaserepository<HealthCareInfo> healthCareInfo)
        {
            _healthCareInfo = healthCareInfo;
        }

        public async Task<APIResult<int>> Handle(HealthCareDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
           var list=await _healthCareInfo.GatAsync();
            var obj = list.FirstOrDefault(m=>m.HealthCareInfoId==request.HealthCareInfoId);
            obj.DeleteIs=true;
            var entity = await _healthCareInfo.UpdateAsync(obj);
            return await Task.FromResult(result.Success(entity));
        }
    }
}
